﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Twinkle.Controls
{
    public class TInputTextBox : Krile.Common.Suggestor.SuggestableTextBox
    {
        public void UpdateColor()
        {
            this.RefreshOverflowColoring();
        }

        public int TagLength { get; set; }

        public override int TextMaxLimitLength
        {
            get
            {
                if (TagLength == 0)
                    return 140;
                else
                    return 139 - TagLength;
            }
        }
        
        public override char[] SuggestCandidates
        {
            get
            {
                if (Kernel.Config.Behavior.UseSuggest)
                    return new[] { '@', '#' };
                else
                    return null;
            }
        }

        public override Krile.Common.Suggestor.SuggestList GetList(char hitCandidate, int targetStart, System.Drawing.Point showLocation)
        {
            if (!Kernel.Config.Behavior.UseSuggest)
                return null;
            if (hitCandidate == '@')
            {
                var nlist = new Krile.Common.Suggestor.SuggestList(this, showLocation);
                nlist.SetItem(Kernel.Storage.GetUsers());
                return nlist;
            }
            else if (hitCandidate == '#')
            {
                var nlist = new Krile.Common.Suggestor.SuggestList(this, showLocation);
                nlist.SetItem(Kernel.Storage.GetHashtags());
                return nlist;
            }
            else
            {
                throw new ArgumentException("Hit candidate must be '@' or '#'.");
            }
        }
    }
}
